package com.itheima.reggie.utils;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;

/**
 * 短信发送工具类
 */
public class SMSUtils {
   /**
    * 发送短信
    *  签名
    *  模板
    * @param phoneNumbers 手机号
    * @param code 参数
    */
   public static void sendMessage(String phoneNumbers,String code){
      DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI5tDMaCBZFaUSLRyB2ZeC", "bWDgXA4nCrgsJFs5iWY5fcAKL1pY6X");
      IAcsClient client = new DefaultAcsClient(profile);

      SendSmsRequest request = new SendSmsRequest();
      request.setSysRegionId("cn-hangzhou");
      request.setPhoneNumbers(phoneNumbers);
      request.setSignName("传智播客");
      request.setTemplateCode("SMS_227120103");
      request.setTemplateParam("{\"code\":\""+code+"\"}");
      try {
         SendSmsResponse response = client.getAcsResponse(request);
         System.out.println("短信发送成功: "+response.getMessage());
      }catch (ClientException e) {
         e.printStackTrace();
      }
   }

   public static void main(String[] args) {
      SMSUtils.sendMessage("159********","6666");
   }
}